package service;

import cn.hutool.core.lang.Singleton;
import tool.RobotTool;
import view.HomePage;

import java.awt.*;

/**
 * @author zhangpeiwen
 * @since 2020/10/2
 */
public class WakeOrHideService {
    private HomePage homePage = Singleton.get(HomePage.class);

    public void wakeOrHide(){
        homePage.setVisible(!homePage.isVisible());
        if(homePage.isVisible()){
            // 这里暂时没实现，影响的功能是，没获得焦点，导致点击其他地方的时候，无法触发focus lost自动隐藏窗体
            // TODO: 2020/10/1 request focus here
                homePage.requestFocusInWindow();
                homePage.requestFocus();

//                KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
//                homePage.getRootPane().grabFocus();
//                homePage.getLayeredPane().grabFocus();
//                focusManager.clearGlobalFocusOwner();
//            Point windowLocation = homePage.getLocationOnScreen();
//            RobotTool.click((int)windowLocation.getX(), (int)windowLocation.getY());

            System.out.println("拿到没？ " + homePage.hasFocus());
            System.out.println("isActive？ " + homePage.isActive());
        }
    }
}
